﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

namespace BtoBSWT315.Company
{
    public partial class Default : System.Web.UI.Page
	{
        //分页
        public int CompanyID;
        public static int TotalRecord;
 
        protected System.Web.UI.WebControls.Image Image1;
        protected System.Web.UI.WebControls.HyperLink HyperLink1;
        protected System.Web.UI.WebControls.HyperLink HyperLink2;
        public static int PageCount;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            if (!IsPostBack)
            {
                HitsDataBind();
                QYDataBind();
                CPDataBind();
                GQDataBind();

            }
        }

        private void HitsDataBind()
        {
            int ID = Convert.ToInt32(Request.QueryString["ID"]);
            //定义所需SQL
            string sql = "update qyml set hits=hits+1 where ID=" + ID;
            //引入数据库操作类
            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
            classdb.GetNonResult(sql);
        }

        private void QYDataBind()
        {
            //SP"QYView" 对应的表是：Qyml
            int ID = Convert.ToInt32(Request.QueryString["ID"]);
            CompanyID = ID;

            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
            string sql = "select qymc,qyjj from qyml where ID=" + ID;


            DataTable dataTable=classdb.GetTables(sql);
            if (dataTable != null && dataTable.Rows.Count > 0)
            {
                lblCompanyName.Text = dataTable.Rows[0]["qymc"].ToString();
                qyjj.Text = dataTable.Rows[0]["qyjj"].ToString();
            }

            //DataTable dataTable = null;
            //dataTable = classdb.GetTables(sql);
            //if (dataTable != null && dataTable.Rows.Count != 0)
            //{

            //    //qyjj.Text = dataTable.Rows[0]["qyjj"].ToString();

            //    //foreach (DataRow row in dataTable.Rows)
            //    //{
            //    //   // Literal1.Text = row["qymc"].ToString();
            //    //    //qymc.Text = row["qymc"].ToString();				//企业名称
            //    //    //qymc1.Text = row["qymc"].ToString();				//企业名称
            //    //    qyjj.Text = row["qyjj"].ToString();


                   

            //    //   // HyperLink1.NavigateUrl = "Jop.aspx?ID=" + ID;
            //    //    //HyperLink2.NavigateUrl = "Connection.aspx?ID=" + ID;



            //    //}


            //   // splabel.Text = "<strong>商铺首页</strong>&gt;&gt;";
            //    dataTable.Clear();
            //    //TODO:Check Dispose
            //    dataTable.Dispose();
            //}
            //else
            //{
            //    //TODO:Add logics
            //   // splabel.Text = "暂无数据";
            //}
        }

        //产品绑定
        private void CPDataBind()
        {
            int ID = Convert.ToInt32(Request.QueryString["ID"]);

            //引入数据库操作类
            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
            //定义所需sql语句
            string sql = "select id,cpmc,picture from spzs where Gsid=" + ID;
            sql += "  order by id desc";
            //取得结果值
            DataList1.DataSource = classdb.GetTables(sql).DefaultView;
            DataList1.DataBind();

        }

        private void GQDataBind()
        {
            int ID = Convert.ToInt32(Request.QueryString["ID"]);

            //引入数据库操作类
            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
            //定义所需sql语句
            //string sql="select Info_ID,showname,picture from InFo where Gsid="+ID;
            string sql = "select Info_ID,type,showname,dateandtime from InFo where Gsid=" + ID;
            sql += "  order by info_id desc";

            //创建数据适配器
            OleDbDataAdapter sda = classdb.Getda(sql);

            //创建数据集
            DataSet ds = new DataSet();

            //填充数据集
            sda.Fill(ds, "tablejyz");

            if (ds.Tables["tablejyz"].Rows.Count > 0)
            {

                //创建分页类
                PagedDataSource objPage = new PagedDataSource();
                //设置数据源
                objPage.DataSource = ds.Tables["tablejyz"].DefaultView;
                //允许分页
                objPage.AllowPaging = true;
                //设置每页显示的项数
                objPage.PageSize = 12;

                TotalRecord = ds.Tables["tablejyz"].Rows.Count;//总共多少条记录
                lblRecordCount.Text = ds.Tables["tablejyz"].Rows.Count.ToString();

                PageCount = (TotalRecord + objPage.PageSize - 1) / objPage.PageSize;//总共多少页
                lblPageCount.Text = "共" + PageCount.ToString() + "页";

                //定义变量用来保存当前页索引
                int CurPage;
                //判断是否具有页面跳转的请求
                if (Request.QueryString["Page"] != null)
                    CurPage = Convert.ToInt32(Request.QueryString["Page"]);
                else
                    CurPage = 1;
                //设置当前页的索引
                objPage.CurrentPageIndex = CurPage - 1;

                //显示状态信息
                lblCurPage.Text = "当前页：第" + CurPage.ToString() + "页";

                //如果当前页面不是首页
                if (!objPage.IsFirstPage)
                {
                    //定义"上一页"超级链接的URL为：当前执行页面的虚拟路径,并传递下一页面的索引值
                    lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
                    //lnkPrev.NavigateUrl += "&ID=" + ID;
                    lnkPrev.NavigateUrl += "&ID=" + CompanyID;

                }
                //如果当前页面不是最后一页
                if (!objPage.IsLastPage)
                {

                    //定义"下一页"超级链接的URL为：当前执行页面的虚拟路径,并传递下一页面的索引值
                    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
                    //lnkNext.NavigateUrl += "&ID=" + ID;
                    lnkNext.NavigateUrl += "&ID=" + CompanyID;
                }

                FistPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
                //FistPage.NavigateUrl += "&ID=" + ID;
                FistPage.NavigateUrl += "&ID=" + CompanyID;

                EndPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + PageCount;
                //EndPage.NavigateUrl += "&ID=" + ID;
                EndPage.NavigateUrl += "&ID=" + CompanyID;


                //进行数据绑定
                Datalist2.DataSource = objPage;
                Datalist2.DataBind();
            }
            else
            {
                lblMessage.Text = "暂无数据！";
                lblPageCount.Text = "0";
            }


        }


        protected string GetImageUrl(string imgUrl)
        {
            imgUrl = imgUrl.Replace("..", "~/");
            imgUrl = imgUrl.Replace("\\", "/");
            imgUrl = imgUrl.Trim();
            return imgUrl;
        }


        protected string GetTitle(string Title)
        {
            if (Title.Length > 9)
            {
                Title = Title.Substring(0, 9);
            }
            return Title;
        }
	}
}